﻿using Rainbow.core;
using Rainbow.model;
using System.Windows;
using System.Windows.Controls;

namespace Rainbow.view
{
    /// <summary>
    /// GlobalSettingDlg.xaml 的交互逻辑
    /// </summary>
    public partial class GlobalSettingDlg : Window
    {
        public GlobalSettingDlgViewModel windowViewModel {  get; set; }

        public GlobalSettingDlg()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(Window_Loaded);
            this.Unloaded += new RoutedEventHandler(Window_UnLoaded);

            this.btnOK.Click += new RoutedEventHandler(OK_Click);
            this.btnCancel.Click += new RoutedEventHandler(Cancel_Click);

            windowViewModel = new GlobalSettingDlgViewModel();
            this.DataContext = windowViewModel;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void Window_UnLoaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            bool chkFlag = Check();
            if (!chkFlag) return;

            this.DialogResult = true;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private bool Check()
        {
            bool hasError = (Validation.GetHasError(tbRootPath));

            return !hasError;
        }
    }

    public class GlobalSettingDlgViewModel : ViewModelBase
    {
        public GlobalSettingDlgViewModel()
        {
            globalSetting = new GlobalSettingViewModel(TW_App.globalSetting.Clone());
        }

        private GlobalSettingViewModel m_globalSetting;
        public GlobalSettingViewModel globalSetting
        {
            get { return m_globalSetting; }
            set
            {
                m_globalSetting = value;
                NotifyPropertyChanged();
            }
        }
    }
}
